package net.myspring.middle.mapper;

import net.myspring.common.mybatis.domain.Page;
import net.myspring.common.mybatis.domain.Pageable;
import net.myspring.common.mybatis.provider.mapper.CrudMapper;
import net.myspring.middle.domain.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;
import java.util.Map;

/**
 * Created by liuj on 16/7/10.
 */
@Mapper
public interface PermissionMapper extends CrudMapper<Permission,String> {

    List<String> findCodeByAccountId(String accountId);

    List<String> findMenuIdByAccountId(String accountId);

    List<Permission> findByMenuId(String id);

    Permission findByCode(String code);

    Page<Permission> findPage(Pageable pageable, @Param("p") Map<String, Object> map);

    List<Permission> findByRoleId(String roleId);

    int deleteByIdNotIn(@Param("ids") List<String> ids);

    List<Permission> findAll();

    @Cacheable(value = "permissions", key = "#p0")
    Permission findOne(String id);

    @CacheEvict(value = "permissions", key = "#p0.id")
    int update(Permission permission);

    int deleteAll();
}
